package com.example.hasee.zhcd.Adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.hasee.zhcd.Activities.ChuanWu.LPEntrustActivity;
import com.example.hasee.zhcd.Activities.ChuanWu.LPInnerActivity;
import com.example.hasee.zhcd.Activities.ChuanWu.OBInputActivity;
import com.example.hasee.zhcd.R;
import com.example.hasee.zhcd.Util.GlobalParameter;

import java.util.ArrayList;
import java.util.HashMap;


/**
 * Created by hasee on 2017/9/13.
 */

public class OutBusinessAdapter extends BaseAdapter {
    private HashMap<String, String> map = (HashMap<String, String>) GlobalParameter.get("loginmap");
    private ArrayList<HashMap<String, String>> list;
    private LayoutInflater itemInflater;
    private Context context;
    private Holder holder;

    public OutBusinessAdapter(Context context, ArrayList<HashMap<String, String>> list) {
        this.context = context;
        this.list = list;
        this.itemInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            holder = new Holder();
            convertView = itemInflater.inflate(R.layout.out_list_item, null);
            holder.bowei = (TextView) convertView.findViewById(R.id.bowei);
            holder.chuanming = (TextView) convertView.findViewById(R.id.chuanming);
            holder.hangci = (TextView) convertView.findViewById(R.id.hangci);
            holder.denglunshijian = (TextView) convertView.findViewById(R.id.denglunshijian);
            holder.denglunmudi = (TextView) convertView.findViewById(R.id.denglunmudi);
            holder.tongzhineirong = (TextView) convertView.findViewById(R.id.tongzhineirong);
            holder.beizhu = (TextView) convertView.findViewById(R.id.beizhu);
            holder.xiugai = (TextView) convertView.findViewById(R.id.xiugai);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }

        holder.bowei.setText((String) list.get(position).get("fberth"));
        holder.chuanming.setText((String) list.get(position).get("fshipname"));
        holder.hangci.setText((String) list.get(position).get("fdly"));
        holder.denglunshijian.setText((String) list.get(position).get("fdlsj"));
        holder.denglunmudi.setText((String) list.get(position).get("fdlmd"));
        holder.tongzhineirong.setText((String) list.get(position).get("ftznr"));
        holder.beizhu.setText((String) list.get(position).get("fbz"));
        if (list.get(position).get("fxx").length() == 0) {
            holder.xiugai.setVisibility(View.INVISIBLE);
        } else {
            holder.xiugai.setText(list.get(position).get("fxx") + ">>");
            holder.xiugai.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, OBInputActivity.class);
                    //{"fid":"32150", "fberth":"904", "fshipname":"广茂", "fhc":"1808", "fdlsj":"06-05 18:20", "fdly":"陈义军",
                    // "fdlmd":"其他事项", "ftznr":"其他事项:换运单,", "fsyn":"QHD201802254", "fbz":""}
                    intent.putExtra("fsyn", list.get(position).get("fsyn"));
                    intent.putExtra("fid", list.get(position).get("fid"));
                    intent.putExtra("fshipname", list.get(position).get("fshipname"));
                    intent.putExtra("fshipcode", list.get(position).get("fshipcode"));
                    intent.putExtra("ftznr", list.get(position).get("ftznr"));
                    intent.putExtra("fbz", list.get(position).get("fbz"));
                    intent.putExtra("add", false);
                    context.startActivity(intent);
                }
            });
        }

        return convertView;
    }

    class Holder {
        private TextView bowei;
        private TextView chuanming;
        private TextView hangci;
        private TextView denglunshijian;
        private TextView denglunmudi;
        private TextView tongzhineirong;
        private TextView beizhu;
        private TextView xiugai;
    }
}
